<?php
namespace Admin\Controller;
use Think\Controller;
header("content-type:text/html;charset=utf-8");
class UserController extends Controller {
	public function userList(){
		$sear=I('post.search');
		$map['uname']=array('like',"%$sear%");
		$count = M('users')->count();
		$size = 3;
		$pagenums = ceil($count/$size);
		$this->assign('sear',$sear);
		$this->assign('pagenums',$pagenums);
		$this->display();
	} 
    public function del(){
		$uid = I('uid');
		$re = M('users')->delete($uid);
		$r=array();
		if($re){
			$r['msg']="删除成功";
			$r['state']=true;
		}else{
			$r['msg']="删除失败";
			$r['state']=false;
		}
		$this->ajaxReturn($r);
		
	}
	public function query(){
		$uid=I('uid');
		$res=M('users')->find($uid);
		$this->ajaxReturn($res);
	
	}
	public function edit(){
		$user = D('users');
		$user->create();
		if($user->save()){
			$r['msg']='修改成功';
			$r['state']=true;
		}else{
			$r['msg']='修改失败';
			$r['state']=false;
		}
		$this->ajaxReturn($r);
	}
	public function search(){
		$term = I('get.term');
		$res=M('users')->field('uname')->where(array('uname'=>array('like',"%{$term}%")))->select();
		
		$str = "[";
		foreach($res as $v){
			$str .= '"'.$v['uname'].'",';
		}
		$str = rtrim($str,',');
		$str .= "]";
		echo $str;
	}
	public function queryUser(){
		$sear=I('get.sear');
		$map['uname']=array('like',"%$sear%");
		$res = M('users')->where($map)->page(I('get.p'),3)->select();
		$this->ajaxReturn($res);
	}
	
		
}
   
	
	
